
#ifndef COLOR_GUI_CONFIG_H__
#define COLOR_GUI_CONFIG_H__ 

#include "app_section.h"
#include "log.h"

// #include "log.h"

// <<< Use Configuration Wizard in Context Menu >>>\n

// ==========================================================================================
// <h> LCD Parameters  
// ==========================================================================================

// <o> lcd/oled resolution horizon 
// <96=>96 pixels
// <128=>128 pixels
// <240=>240 pixels 
// <280=>280 pixels
// <320=>320 pixels
// <360=>360 pixels
#define GUI_LCD_RES_H           360

// <o> lcd/oled resolution vertical
// <96=>96 pixel 
// <128=>128 pixels
// <240=>240 pixels 
// <280=>280 pixels
// <280=>280 pixels
// <320=>320 pixels
// <360=>360 pixels
#define GUI_LCD_RES_V          360 

// <o> Bits of pixel
// <i> bits of pixel, if 
// <1=> 1bits, Mono
// <8=> 8bits, RGB332
// <16=> 16bits, RGB565
// <24=> 24bits, RGB888
// <32=> 32bits, ARGB8888
#define GUI_LCD_PIXEL_BITS      (16)

// pixel bytes, calculate by bits, if bits little than 8, should not use bytes 
#define GUI_LCD_PIXEL_BYTES     ((GUI_LCD_PIXEL_BITS + 7) / 8 )

#define GUI_GET_PITCH(x)            (((x) + 7) / 8)


// </h> !LCD base parameters 
// ==========================================================================================

// ==========================================================================================
// <h> Platform  
// ==========================================================================================
// <i> always requires RAM to store 1 or multi row UI raw data 

// <q> support XIP
// <i> xip - execute in progress 
// <i> if support xip, some data will not load buffer 
// <i> if not support xid, image for rorate & font required to load raw data or read while need, and this will cost more time 
#define GUI_IS_SUPPORT_XIP                     1


// <q> use ram code 
// <i> put gui function into RAM to accelerate execute speed 
#define GUI_USE_RAM_CODE                1 

#if     GUI_USE_RAM_CODE 
#define GUI_RAM_CODE            DATA_RAM_FUNCTION
#else 
#define GUI_RAM_CODE
#endif 

// add section on sct files 
#if defined( __CC_ARM )
#define GUI_MENU_SECTION     __attribute__((section(".app.flash.gui_menu")))  __attribute__((used))
#else 
#define GUI_MENU_SECTION
#endif 

#if defined( __CC_ARM )
#define __GUI_INLINE        inline
#else 
#define __GUI_INLINE
#endif 

#if defined( __CC_ARM )
#define GUI_ALIGN_PACK(x)       __attribute__((aligned(x))) 
#else 
#define GUI_ALIGN_PACK(x)
#endif 
    
// used for porting notify upper that framebuffer is ready, invalidate.
#define GUI_INVALIDATE()        

// used for poriting, notify uppert that part of framebuffer is ready, invalidate parts. 
#define GUI_INVALIDATE_PART(x,y,w,h)    

// <o> frame buffer section rows
// <i> if memory is not enough to store a frame image, GUI will 
// <i> draw image seprately.
// <i> suggest to multiple time to lcd height 
// <1-360> 
#define GUI_FRAME_BUFFER_ROWS              8

// frame buffer require OP nums to update a total sreen
// equal to (h / fb_rows)
#define GUI_FRAME_BUFFER_REQ_NUMS               ((GUI_LCD_RES_V + GUI_FRAME_BUFFER_ROWS - 1) / GUI_FRAME_BUFFER_ROWS )

// <q> turn off display while update 
// <i> if update is too slow, suggest to turn off display while update 
// <i> turn on display after update done 
#define GUI_UPDATE_LCD_TURN_OFF         0 

// <q> use Sync Signal 
#define GUI_USER_SYNC_HANDLER           0 

// <o> update part count(Max)
// <1-16>
// <i> how much parts cans specify in a view to refresh 
#define GUI_UPDATE_PART_NUM             8

// <o> Max count of widget in a view 
// <10-64>
// <i> the number is bigger, and RAM used mucher 
#define GUI_WIDGETS_MAX_CNT             32

// <e> image use buffer 
// <i> under image rotation, suggest to use buffer to load raw image first 
// <i> to accelerate algorithm for average color 
#define GUI_IMAGE_USE_BUFFER            0

#if GUI_IMAGE_USE_BUFFER

#define GUI_MEM_MALLOC                   // if must define a function to assign ram 
#define GUI_MEM_FREE                     

#endif 

// </e> !image use buffer 

// <e> view switch use effects 
#define GUI_USE_EFFECTS         1

// <e> slide animate 
#define GUI_EFFECTS_NAVIGATE_SLIDE_ANIMATE       1 


// <o> slide step count
// <1-12> 
#define GUI_STEP_COUNT                  6

#define GUI_MINI_STEPS                  ((GUI_LCD_RES_H + GUI_STEP_COUNT - 1)  / GUI_STEP_COUNT ) 

// </e> !slide animate 

// <q> drag animate
#define GUI_EFFECTS_DRAG_ANIMATE        0 

// </e> view switch use effects 



// </h> !LCD update option 
// ==========================================================================================



// ==========================================================================================
// <h> GUI resource setting
// ==========================================================================================

// <o> Image assets minimum version required
// <i> image assets has version while generated.
#define GUI_IMAGES_ASSETS_MIN_VERSION_REQUIRED       0x0001

// <o> Charmap assets minimum version required
#define GUI_CHARMAP_ASSETS_MIN_VERSION_REQUIRED      0x0001

// <o> Resource Base Address
#define FLASH_BASE_ADDR                 0x00800000

// <o> Picture Resource start address
// <i> while download pic resource, remember to add base-address(defined by MCU) 
// <i> if used 
#define GUI_PIC_RES_START_ADDRESS       (FLASH_BASE_ADDR + 0x100000) // 0x160000 , 0x200000

#define GUI_PIC_RES_IMAGE_START_OFFSET (GUI_PIC_RES_START_ADDRESS + 0x30)

// <o> Font library start address
// <i> while download pic resource, remember to add base-address(defined by MCU) 
#define GUI_FONT_LIBRARY_HEADER_ADDRESS (FLASH_BASE_ADDR + 0x600000)

#define GUI_FONT_LIBRARY_START_ADDRESS  (GUI_FONT_LIBRARY_HEADER_ADDRESS + 0x30)

// <s> Font header c file
#define GUI_FONT_LIB_HEADER_C       "gui_configs/header.c"
 

// <q> internal font used
#define GUI_IFONT_USED                  1

// <s> Internal font library c file
#define GUI_IFONT_LIB_FILE              "gui_configs/IFONT.c"

#define GUI_GET_IMAGE_START_ADDR()      (GUI_PIC_RES_START_ADDRESS)
#define GUI_GET_IMAGE_HEADER_ADDR()   (GUI_PIC_RES_START_ADDRESS)
#define GUI_GET_IMAGE_ADDR(x)       ( (x) + GUI_PIC_RES_IMAGE_START_OFFSET) 

#define GUI_GET_CHARMAP_START_ADDR()       (GUI_FONT_LIBRARY_HEADER_ADDRESS)
#define GUI_GET_CHARMAP_ADDR( OFFS)        ( GUI_FONT_LIBRARY_HEADER_ADDRESS + (OFFS) )
#define GUI_GET_CHARMAP_START( OFFS )       ( (OFFS) )


// </h> LCD resource definiation 

// ==========================================================================================
// <h> UI Widgets Options
// ==========================================================================================

#define WIDGET_CHECK_IS_ENABLE(x)         GUI_WIDGET_##x

// <q> Bitmap used
#define GUI_WIDGET_BITMAP               1

// <q> Canvas used
#define GUI_WIDGET_CANVAS               1

// <q> Stack used
#define GUI_WIDGET_STACK                1 

// <q> ChartBar used
#define GUI_WIDGET_CHARTBAR             0

// <q> ChartCurve used
#define GUI_WIDGET_CHARTCURVE           0

// <q> ChartCurveItem used
#define GUI_WIDGET_CHARTCURVEITEM       0 

// <q> ChartColumn used
#define GUI_WIDGET_CHARTCOLUMN          0 

// <q> Circlebar  used
#define GUI_WIDGET_CIRCLEBAR            1 

// <q> ColorReplacer used
#define GUI_WIDGET_COLORREPLACER        1 

// <q> Digital used
#define GUI_WIDGET_DIGITAL              1 

// <e> Digital List  used
#define GUI_WIDGET_DIGITALLIST          1 

// <o> Digital List Support max count
#define GUI_DIGITALLIST_ITEM_NUM_MAX        6 

// </e> !Digital List 

// <q> Grid  used
#define GUI_WIDGET_GRID                 1

// <q> Label  used
#define GUI_WIDGET_LABEL                1 

// <q> List used
#define GUI_WIDGET_LISTBOX              1

// <q> Matrix  used
#define GUI_WIDGET_MATRIX               1 

// <q> Number  used
#define GUI_WIDGET_NUMBER               1 

// <q> NumberList  used
#define GUI_WIDGET_NUMBERLIST           1 

// <q> Panel used
#define GUI_WIDGET_PANEL                1 

// <q> Picker used
#define GUI_WIDGET_PICKER                1
 
// <q> Picture  used
#define GUI_WIDGET_PICTUREBOX           1 

// <q> Picture Internal used
// <i> Picture address from code, not form image resource            
#define GUI_WIDGET_PICTUREINTERNAL      1

// <q> Pointer  used
#define GUI_WIDGET_POINTER              1

// <q> Progressbar  used
#define GUI_WIDGET_PROGRESSBAR          1 

// <e> Qrcode used
#define GUI_WIDGET_QRCODE               1 

// <o> Qrcode Max version
// <1=>1
// <2=>2
// <3=>3
// <i> refer to https://blog.csdn.net/gd2008/article/details/8509149
#define GUI_QRCODE_VERSION_MAX          1

#define GUI_QRCODE_MAX_SIZE             (21 + (GUI_QRCODE_VERSION_MAX - 1) * 4)

// </e> !Qrcode

// <q> Switch used
#define GUI_WIDGET_SWITCH               1 

// <q> Textbox used
#define GUI_WIDGET_TEXTBOX              1 

// <q> TextPage used
#define GUI_WIDGET_TEXTPAGE             1 

// <q> TextScroll used
#define GUI_WIDGET_TEXTSCROLL           1 

// <q> Touch used
#define GUI_WIDGET_TOUCH                1 



// </h> UI widgets 
// ==========================================================================================

// <h> GUI LOG

// <q> Stopwatch debug enable
#define GUI_STOPWATCH_DEBUG_ENABLE      0

// <q> LOG Enable
// <i> if enable LOG function,  GUI LOG
// <i> if disable LOG, GUI LOG 
#define GUI_LOG_ENABLE                  1


#if GUI_LOG_ENABLE

#include "log.h"
#define GUI_LOG             LOG_INFO0 // GUI Log function 
#define GUI_LOG0            LOG_INFO0
#define GUI_LOG1            LOG_INFO1
#define GUI_LOG2            LOG_INFO2
#define GUI_LOG3            LOG_INFO3
#define GUI_LOG4            LOG_INFO4

#define GUI_TRACE_STR( s )       FORMAT_STRING(s)

#define GUI_ASSERT(x, msg)   do{\
                            if( x ) {\
                                GUI_LOG3("[GUI ERROR]: [%s] at LINE %d ==>%s", GUI_TRACE_STR(__FUNCTION__), __LINE__, GUI_TRACE_STR(msg) );\
                                return;\
                            }\
                        }while(0) 

#define GUI_ASSERT_BOOLEAN(x, msg, xBOOL) do{\
                            if( x ) {\
                                GUI_LOG3("[GUI ERROR]: [%s] at LINE %d ==>%s", GUI_TRACE_STR(__FUNCTION__), __LINE__, GUI_TRACE_STR(msg) );\
                                return xBOOL;\
                            }\
                        }while(0)                         
#else

#define GUI_LOG(...) 
#define GUI_LOG0(...)
#define GUI_LOG1(...)
#define GUI_LOG2(...)
#define GUI_LOG3(...)
#define GUI_LOG4(...)

#define GUI_TRACE_STR(...)

#define GUI_ASSERT(...)       
#define GUI_ASSERT_BOOLEAN(...)

#endif 


                            
// </h> !Debug



// <<< end of configuration section >>>

#endif 
